#include <curses.h>
#include <stdlib.h>
#include "endscreen.h"

int* load_highscores() {
	FILE* file;
	if ((file = fopen(HIGHSCORE_FILE, "r")) == 0) {
		int* ret = malloc(sizeof(int));
		ret[0] = 0;
		return ret;
	}
	return NULL;
}

void display_endscreen(int currentScore) {
	if (2 * 40 > COLS || 20 > LINES) {
                endwin();
                fprintf(stderr, "Snek: Terminal is to small, must be 80x20 at least\n");
                exit(1);
        }
	WINDOW* win = subwin(stdscr, 20, 80, 0, 0);
	clear();
	wattrset(win, COLOR_PAIR(7));
	mvwprintw(win, 1, 1, "GAME OVER! YOUR SCORE: %d", currentScore);
	mvwprintw(win, 2, 1, "Press SPACEBAR to play again, q to quit");
	wrefresh(win);
	nodelay(stdscr, FALSE);
	while(1) {
		char c = getch();
		switch(c) {
			case ' ':
				nodelay(stdscr, TRUE);
				delwin(win);
				return;
			case 'q':
				endwin();
				exit(0);
			default:
				break;
		}
	}
}

